﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JoinParty.BLL;
using MySql.Data.MySqlClient;
using ZHDJ.Core;
using ZHDJ.WebPage;
using ZHDJ.Data.Models.JoinParty;

namespace JoinParty.Template
{
    public partial class TJoinStep15 : TemplatePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {


                LoadData();
            }
        }

        public string StepID
        {
            get { return Request.QueryString["StepID"]; }
        }

        public string JID
        {
            get { return Request.QueryString["JID"]; }
        }

        public string FileName { get; set; }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (PartyOrgMember == null || PartyJoinApplycation == null)
                return;
            WordBusiness.Export(this, palWord, PartyOrgMember.UserName + "--" + "政治审查.doc");
        }

        public void LoadData()
        {
            if (PartyOrgMember == null || PartyJoinApplycation == null)
                return;
            FileName = PartyOrgMember.UserName + "--" + "政治审查.doc";
            litUserName.Text = PartyOrgMember.UserName;
            litBeforeName.Text = PartyJoinApplycation.BeforeName;
            litSex.Text = PartyOrgMember.Gender == "0" ? "男" : "女";
            if (PartyOrgMember.Birthday != null)
                litBirthday.Text = Convert.ToDateTime(PartyOrgMember.Birthday).ToString("yyyy-MM-dd");
            litBenrenchenfen.Text = PartyJoinApplycation.Nature;
            litNation.Text = PartyOrgMember.Nation;
            litNativePlace.Text = PartyOrgMember.NativePlace;
            if (PartyOrgMember.PoliticsLineament != "")
            {
                var firstOrDefault = DB.DataDictionarys.FirstOrDefault(a => a.DDicMember == PartyOrgMember.PoliticsLineament && a.DDicType == SysDataDictionary.MemberPoliticsLineamentKey);
                if (
                    firstOrDefault != null)
                    litPoliticsLineament.Text = firstOrDefault.DDicMemberName;
            }

            litEducational.Text = PartyOrgMember.Educational;
            litWorkUnit.Text = PartyOrgMember.WorkUnit;
            litUnitJob.Text = PartyOrgMember.UnitJob;
            litAddress.Text = PartyOrgMember.Address;
            if (this.StepID == "JoinStep16")
            {
                if (GetBiaoxian() != null && GetBiaoxian().Rows.Count > 0)
                {
                    litBiaoxian.Text = GetBiaoxian().Rows[0]["Remark"].ToString();
                    this.litTitle.Text = GetBiaoxian().Rows[0]["Title"].ToString();
                }
            }
            else
            {
                var exam = DB.partyjoinexaminations.Find(this.JID);
                if (exam != null)
                {
                    litTitle.Text = exam.Title;
                    this.litBiaoxian.Text = exam.Content;
                }
            }
        }

        public DataTable GetBiaoxian()
        {
            var para = new List<MySqlParameter>
            {
                new MySqlParameter()
                {
                    DbType = DbType.String,
                    ParameterName = "AppllicationID",
                    Value = PartyJoinApplycation.AppllicationID
                }
            };
            string sql =
                @"SELECT StandID as ID,`DATA`.Remark ,`DATA`.AppllicationID,CONCAT('关于',app.UserName,'同志的',substring(`DATA`.CurrentStepName,4),'证明') as Title,'JoinStep16' as StepID from tblpartyjoinlinkexample DATA
LEFT JOIN tblpartyjoinapplycation app on `DATA`.AppllicationID=app.AppllicationID
where DATA.appllicationID='8d738cb6e9e440eeb71c334bb5f3910a'  AND CurrentStepID='JoinStep16' AND DATA.`Status`=1  ORDER BY DATA.CreateTime DESC LIMIT 0,1";
            return ZHDJ.Data.MySqlHelper.ExecuteDataTable(sql, para.ToArray());
        }
    }
}